home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gxtext.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  8.9 KB  |  257 lines

  1. /* Copyright (C) 1998, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gxtext.h,v 1.3.2.1 2000/10/26 12:45:12 igorm Exp $ */
  20. /* Driver text interface implementation support */
  21.  
  22. #ifndef gxtext_INCLUDED
  23. #  define gxtext_INCLUDED
  24.  
  25. #include "gstext.h"
  26. #include "gsrefct.h"
  27.  
  28. /*
  29.  * WARNING: The APIs and structures in this file are UNSTABLE.
  30.  * Do not try to use them.
  31.  */
  32.  
  33. /* Define the abstract type for the object procedures. */
  34. typedef struct gs_text_enum_procs_s gs_text_enum_procs_t;
  35.  
  36. /*
  37.  * Define values returned by text_process to the client.
  38.  */
  39. typedef struct gs_text_returned_s {
  40.     gs_char current_char;    /* INTERVENE */
  41.     gs_glyph current_glyph;    /* INTERVENE */
  42.     gs_point total_width;    /* RETURN_WIDTH */
  43. } gs_text_returned_t;
  44.  
  45. /*
  46.  * Define the stack for composite fonts.
  47.  * If the current font is not composite, depth = -1.
  48.  * If the current font is composite, 0 <= depth <= MAX_FONT_STACK.
  49.  * items[0] through items[depth] are occupied.
  50.  * items[0].font is the root font; items[0].index = 0.
  51.  * The root font must be composite, but may be of any map type.
  52.  * items[0..N-1] are modal composite fonts, for some N <= depth.
  53.  * items[N..depth-1] are non-modal composite fonts.
  54.  * items[depth] is a base (non-composite) font.
  55.  * Note that if depth >= 0, the font member of the graphics state
  56.  * for a base font BuildChar/Glyph is the same as items[depth].font.
  57.  */
  58. #define MAX_FONT_STACK 5
  59. typedef struct gx_font_stack_item_s {
  60.     gs_font *font;        /* font at this level */
  61.     uint index;            /* index of this font in parent's Encoding */
  62. } gx_font_stack_item_t;
  63. typedef struct gx_font_stack_s {
  64.     int depth;
  65.     gx_font_stack_item_t items[1 + MAX_FONT_STACK];
  66. } gx_font_stack_t;
  67.  
  68. /*
  69.  * Define the common part of the structure that tracks the state of text
  70.  * processing.  All implementations of text_begin must allocate one of these
  71.  * using rc_alloc_struct_1; implementations may subclass and extend it.
  72.  * Note that it includes a copy of the text parameters.
  73.  *
  74.  * The freeing procedure (rc.free) must call rc_free_text_enum, which
  75.  * calls the enumerator's release procedure.  This is required in order to
  76.  * properly decrement the reference count(s) of the referenced structures
  77.  * (in the common part of the structure, only the device).
  78.  */
  79. rc_free_proc(rc_free_text_enum);
  80. #define gs_text_enum_common\
  81.     /*\
  82.      * The following copies of the arguments of text_begin are set at\
  83.      * initialization, and const thereafter.\
  84.      */\
  85.     gs_text_params_t text;    /* must be first for subclassing */\
  86.     gx_device *dev;\
  87.     gs_imager_state *pis;\
  88.     gs_font *orig_font;\
  89.     gx_path *path;            /* unless DO_NONE & !RETURN_WIDTH */\
  90.     const gx_device_color *pdcolor;    /* if DO_DRAW */\
  91.     const gx_clip_path *pcpath;        /* if DO_DRAW */\
  92.     gs_memory_t *memory;\
  93.     /* The following additional members are set at initialization. */\
  94.     const gs_text_enum_procs_t *procs;\
  95.     /* The following change dynamically.  NOTE: gs_text_enum_copy_dynamic */\
  96.     /* knows the entire list of dynamically changing elements. */\
  97.     rc_header rc;\
  98.     gs_font *current_font; /* changes for composite fonts */\
  99.     gs_log2_scale_point log2_scale;    /* for oversampling */\
  100.     uint index;            /* index within string */\
  101.     uint xy_index;        /* index within X/Y widths */\
  102.     gx_font_stack_t fstack;\
  103.     int cmap_code;        /* hack for FMapType 9 composite fonts, */\
  104.                 /* the value returned by decode_next */\
  105.     gs_point FontBBox_as_Metrics2;  /* used with FontType 9,11 && WMode 1 */\
  106.     /* The following are used to return information to the client. */\
  107.     gs_text_returned_t returned
  108. /* The typedef is in gstext.h. */
  109. /*typedef*/ struct gs_text_enum_s {
  110.     gs_text_enum_common;
  111. } /*gs_text_enum_t*/;
  112.  
  113. #define st_gs_text_enum_max_ptrs (st_gs_text_params_max_ptrs + 7)
  114. /*extern_st(st_gs_text_enum); */
  115. #define public_st_gs_text_enum()    /* in gstext.c */\
  116.   gs_public_st_composite(st_gs_text_enum, gs_text_enum_t, "gs_text_enum_t",\
  117.     text_enum_enum_ptrs, text_enum_reloc_ptrs)
  118.  
  119. /* 
  120.  * Initialize a newly created text enumerator.  Implementations of
  121.  * text_begin must call this just after allocating the enumerator.
  122.  * Note that this procedure can return an error, e.g., if attempting
  123.  * a glyph-based operation with a composite font.
  124.  */
  125. int gs_text_enum_init(P10(gs_text_enum_t *pte,
  126.               const gs_text_enum_procs_t *procs,
  127.               gx_device *dev, gs_imager_state *pis,
  128.               const gs_text_params_t *text,
  129.               gs_font *font, gx_path *path,
  130.               const gx_device_color *pdcolor,
  131.               const gx_clip_path *pcpath,
  132.               gs_memory_t *mem));
  133.  
  134. /*
  135.  * Copy the dynamically changing elements from one enumerator to another.
  136.  * This is useful primarily for enumerators that sometimes pass the
  137.  * operation to a subsidiary enumerator.  Note that `returned' is copied
  138.  * iff for_return is true.
  139.  */
  140. void gs_text_enum_copy_dynamic(P3(gs_text_enum_t *pto,
  141.                   const gs_text_enum_t *pfrom,
  142.                   bool for_return));
  143.  
  144. /*
  145.  * Define some convenience macros for testing aspects of a text
  146.  * enumerator.
  147.  */
  148.  
  149. #define SHOW_IS(penum, op_mask)\
  150.   (((penum)->text.operation & (op_mask)) != 0)
  151. #define SHOW_IS_ALL_OF(penum, op_mask)\
  152.   (((penum)->text.operation & (op_mask)) == (op_mask))
  153.     /*
  154.      * The comments next to the following macros indicate the
  155.      * corresponding test on gs_show_enum structures in pre-5.24 filesets.
  156.      */
  157. #define SHOW_IS_ADD_TO_ALL(penum)    /* add */\
  158.   SHOW_IS(penum, TEXT_ADD_TO_ALL_WIDTHS)
  159. #define SHOW_IS_ADD_TO_SPACE(penum)    /* wchr != no_char */\
  160.   SHOW_IS(penum, TEXT_ADD_TO_SPACE_WIDTH)
  161. #define SHOW_IS_DO_KERN(penum)        /* do_kern */\
  162.   SHOW_IS(penum, TEXT_INTERVENE)
  163. #define SHOW_IS_SLOW(penum)        /* slow_show */\
  164.   SHOW_IS(penum, TEXT_REPLACE_WIDTHS | TEXT_ADD_TO_ALL_WIDTHS | TEXT_ADD_TO_SPACE_WIDTH | TEXT_INTERVENE)
  165. #define SHOW_IS_DRAWING(penum)        /* !stringwidth_flag */\
  166.   !SHOW_IS(penum, TEXT_DO_NONE)
  167. #define SHOW_IS_STRINGWIDTH(penum)    /* stringwidth_flag > 0 */\
  168.   SHOW_IS_ALL_OF(penum, TEXT_DO_NONE | TEXT_RETURN_WIDTH)
  169.  
  170. /*
  171.  * Define the procedures associated with text processing.
  172.  */
  173. struct gs_text_enum_procs_s {
  174.  
  175.     /*
  176.      * Resync processing from an enumerator that may have different
  177.      * parameters and may be partway through processing the string.  Note
  178.      * that this may only be implemented for certain kinds of changes, and
  179.      * will fail for other kinds.  (We may reconsider this.)  We require
  180.      * pfrom != pte.
  181.      */
  182.  
  183. #define text_enum_proc_resync(proc)\
  184.   int proc(P2(gs_text_enum_t *pte, const gs_text_enum_t *pfrom))
  185.  
  186.     text_enum_proc_resync((*resync));
  187.  
  188.     /*
  189.      * Process the text.  Then client should call this repeatedly until
  190.      * it returns <= 0.  (> 0 means the client must take action: see
  191.      * gstext.h.)
  192.      */
  193.  
  194. #define text_enum_proc_process(proc)\
  195.   int proc(P1(gs_text_enum_t *pte))
  196.  
  197.     text_enum_proc_process((*process));
  198.  
  199.     /*
  200.      * After the implementation returned TEXT_PROCESS_RENDER, determine
  201.      * whether it needs the entire character description, or only the width
  202.      * (escapement).
  203.      */
  204.  
  205. #define text_enum_proc_is_width_only(proc)\
  206.   bool proc(P1(const gs_text_enum_t *pte))
  207.  
  208.     text_enum_proc_is_width_only((*is_width_only));
  209.  
  210.     /*
  211.      * Return the width of the current character (in user space coordinates).
  212.      */
  213.  
  214. #define text_enum_proc_current_width(proc)\
  215.   int proc(P2(const gs_text_enum_t *pte, gs_point *pwidth))
  216.  
  217.     text_enum_proc_current_width((*current_width));
  218.  
  219.     /*
  220.      * Set the character width and optionally the bounding box,
  221.      * and optionally enable caching.
  222.      */
  223.  
  224. #define text_enum_proc_set_cache(proc)\
  225.   int proc(P3(gs_text_enum_t *pte, const double *values,\
  226.     gs_text_cache_control_t control))
  227.  
  228.     text_enum_proc_set_cache((*set_cache));
  229.  
  230.     /*
  231.      * Prepare to retry processing the current character by uninstalling the
  232.      * cache device.
  233.      */
  234.  
  235. #define text_enum_proc_retry(proc)\
  236.   int proc(P1(gs_text_enum_t *pte))
  237.  
  238.     text_enum_proc_retry((*retry));
  239.  
  240.     /*
  241.      * Release the contents of the structure at the end of processing,
  242.      * but don't free the structure itself.  (gs_text_release also does
  243.      * the latter.)
  244.      */
  245.  
  246. #define text_enum_proc_release(proc)\
  247.   void proc(P2(gs_text_enum_t *pte, client_name_t cname))
  248.  
  249.     text_enum_proc_release((*release));
  250.  
  251. };
  252.  
  253. /* Define the default release procedure. */
  254. text_enum_proc_release(gx_default_text_release);
  255.  
  256. #endif /* gxtext_INCLUDED */
  257.